<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>首页</title>
    <link rel="stylesheet" type="text/css" href="../static/plugins/layui/css/layui.css">
    <script src="../static/plugins/layui/layui.js"></script>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <style type="text/css">
    .body {
        padding: 0;
        margin: 0;
    }

    .layui-form {
        position: absolute;
        left: 50%;
        top: 45%;
         width: 600px;
        height: 300px;
        transform: translate(-50%, -50%);
        padding: 20px;
        margin-left: 50px;
        border-radius: 10px;
        box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
    }

    .barcode {
        margin-top: 30px;
    }

    .operate-submit {
        margin-top: 30px;
    }

    h2 {
        text-align: center;
        padding: 20px;
    }
    </style>
</head>

<body>
    
</body>
<script>
layui.use('form', function() {
    var form = layui.form;
    form.on('submit(*)', function(data) {
        var timeStamp = new Date(data.field.date).getTime()
        data.field.cutOffTimeEnd = timeStamp
        $.ajax({
            type: 'POST',
            url: 'http://127.0.0.1:5000/getData',
            async: false,
            contentType: 'application/json', // 如果你发送的是JSON数据
            data: JSON.stringify(data.field),
            success: function(data, textStatus, response) {
                if (response.status == 200) {
                    var data = data.data;
                    let filenameArr = data.filename;
                    if (filenameArr.length > 0) {
                        layui.use('layer', function() {
                            var layer = layui.layer;
                            layer.msg('正在下载中');
                        });
                    }
                    for (var i = filenameArr.length - 1; i >= 0; i--) {
                        window.location = "/download/" + filenameArr[i]
                    }
                }
            },
            error: function(jqXHR, textStatus) {
                console.log("请求失败，请稍后重试!");
            }
        })
        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });
});

layui.use('laydate', function() {
    var laydate = layui.laydate;

    //执行一个laydate实例
    laydate.render({
        elem: '#stop_date' //指定元素
    });
});
</script>

</html>